package com.yince.demo.clockcard.utils;

import com.yince.demo.clockcard.database.Form;
import ohos.data.orm.OrmContext;
import ohos.data.orm.OrmPredicates;

import java.util.List;

public class DatabaseUtils {

    /**
     * delete data
     *
     * @param formId form id
     * @param context data connection
     */
    public static void deleteFormData(long formId, OrmContext context){
        OrmPredicates where=context.where(Form.class);
        where.equalTo("formId",formId);
        List<Form> query=context.query(where);

        if(!query.isEmpty()){
            context.delete(query.get(0));
            context.flush();
        }
    }

    /**
     * add card info
     *
     * @param form card object
     * @param context data connection
     */
    public static void insertFormData(Form form,OrmContext context){
        context.insert(form);
        context.flush();
    }
}
